<!DOCTYPE html>
<html>
<head>
	<div th:include="base-libs-easyui :: base-libs-easyui" />
<title>医疗机构列表</title>

<style type="text/css">
body {
	padding: 0px 10px;
}

a {
	text-decoration: none;
}

.tree-icon{
	display: none;
}

.bt-selected{
	background-color: #D0E9C6;
}
</style>
</head>
<script th:inline="javascript">
    /**读取request中的初始化数据*/
    var jgpzjrxx = [[${jgpzjrxx}]];
</script>
<script type="text/javascript">
	$(function() {
		initView();
		$(this).getZydmCache({
            cacheTables: ["TB_ZY_JGLB"]
			,callback: initData
		});
	});

    function initData(cacheData){
		/*卫生机构类别*/
        var ary = cacheData["TB_ZY_JGLB"];
        var dsTree = $.QuickEasyUIUtils.createTreeList(ary.concat(), ary[0]["SJDM"], "XMDM", "XMMC", "SJDM");
        $("#combTreeWsjglb").combotree("loadData", dsTree);
        $("#btnQuery").trigger("click");
    }

	function queryForm() {
        $("#dgForm").datagrid({url: contextRoot + "/yljgxx/queryPageYljgxx.service"});
	}

	function initView() {
        $("#combTreeWsjglb").combotree({
            height: 36
            ,width: 220
            ,panelWidth: 280
            ,editable: true
			,textField: "XMMC"
			,filter: function(q, node){
                $("#combTreeWsjglb").combotree("clear");
                return node.text.toLowerCase().indexOf(q.toLowerCase()) >= 0;
			}
        });

		$("#dgForm").datagrid({
			idField : "PTJGID",
			fitColumns : true,
			fit : true,
			border : false,
			rownumbers: true,
			singleSelect: true,
			toolbar : "#tb",
			pagination: true,
			loadMsg: "",
			columns : [[
				{
					field : "XZQHMC",
					title : "行政区划"
					,width: 3
				},
				{
					field : "YLJGDM",
					title : "医疗机构代码"
					,width: 4
				},
				{
					field : "YLJGMC",
					title : "医疗机构名称"
					,width: 6
				},
				{
					field : "JGJC",
					title : "机构简称"
					,width: 6
				},
                {
                    field : "WSJGLBMC",
                    title : "机构类别"
                    ,width: 3
                },
                {
                    field : "YYDJMC",
                    title : "机构等级"
                    ,width: 3
                },
				{
					field : "CZ",
					title : "操作"
					,width: 4
                    ,formatter : function(value, row, index){
						var tableToolBar = $("#tableToolBar").html();
						if(!jgpzjrxx){
							var _this = $(tableToolBar);
							$(_this).find("a[action='configZyjr']").remove();
							tableToolBar = _this.prop('outerHTML');
						}
//						$(tableToolBar).find("a[action='configZyjr']").remove();
						return tableToolBar.replace(/PTJGID/g, row["PTJGID"]);
					}
				}
			]]
            ,onBeforeLoad: function(queryParams) {
                var url = $(this).datagrid("options")["url"];
				/*URL不等空时再发送请求*/
                if (!StringUtils.isEmpty(url)) {
                    queryParams["pageSize"] = queryParams["rows"];
                    queryParams["pageNumber"] = queryParams["page"];
                    var params = $("#queryForm").getFormData();
                    params["WSJGLBDM"] = $("#combTreeWsjglb").combotree("getValue");
                    $.extend(queryParams, params);
                    return true;
                }else{
                    return false;
                }
            }
		});
        $("body").on("click", ".tableToolBarBtn", function(){
            var action = $(this).attr("action");
            var PTJGID = $(this).attr("id");
            $("#dgForm").datagrid("selectRecord", PTJGID);
            var row = $("#dgForm").datagrid("getSelected");
            if("update" == action){
                updateYljgxx(row);
            }else if("configZyjr" == action){
                configZyjr(row);
            }else if("query" == action){
                StoreCache.setCache("onlyQuery",true);
                updateYljgxx(row);
			}
        })
	}

	/**修改机构信息*/
	function updateYljgxx(item){
        StoreCache.setCache("cache_yljgxx", item);
        $.QuickUrlUtils.redirectUrl("manager.html");
	}

	/**查询按钮点击回调*/
	function btnQueryHandler() {
		queryForm();
	}

	/**增加按钮回调*/
	function btnAddHandler() {
		$.QuickUrlUtils.redirectUrl("manager.html");
	}
	
	/** 导出Excel文件  */
	function btnDownExcelHandler(){
        var params = $("#queryForm").getFormData();
        params["WSJGLBDM"] = $("#combTreeWsjglb").combotree("getValue");
        var $downForm = $("#downForm");
        $downForm.empty();
        $.each(params, function (key,value) {
            var input = $("<input>").attr({name: key, value: value, type: 'hidden'});
            $downForm.append(input);
        })
		$downForm.submit();
	}

	/**配置资源接入*/
	function configZyjr(item){
        openConfigZyjr(item);
	}

    /**打开配置资源接入页面*/
    function openConfigZyjr(item){
        StoreCache.setCache("cache_zyjr_yljgxx", item);
        var uri = contextRoot + "/yljgxx/configZyjr.html?";
        $.QuickAlert.alertIFrame({
            title: "机构资源接入信息维护"
            ,shadeClose: false
            ,content: uri
            ,width: "760px"
            ,height: "400px"
            ,end: function(){
                StoreCache.removeCache("cache_zyjr_yljgxx", item);
            }
        })
    }
</script>

<body class="easyui-layout">
<div region="north" style="height: 41px; border: none; overflow: hidden; background-color: #f9f9f9;">
	<div style="width: 100%; height: 100%; margin-left: 30px">
		<h3 style="line-height: 41px; margin: 0px; font-size: 18px;font-weight: bold;">机构列表</h3>
	</div>
</div>
<div region="center">
	<div id="tb" style="padding:8px 20px;">
		<form id="queryForm">
			<table>
				<tr>
					<td class="query-text">机构名称</td>
					<td class="query-content">
						<input name="YLJGMC" placeholder="支持机构名称，机构简称，机构全拼，机构简拼" class="query-input" style="width: 300px;">
					</td>
					<td class="query-text">机构类别</td>
					<td class="query-content">
						<input id="combTreeWsjglb">
					</td>
					<td>
						<button id="btnQuery" class="btn btn-default" type="button" onclick="btnQueryHandler()">查询</button>
						<button id="btnAdd" class="btn btn-default" type="button" onclick="btnAddHandler()">新增</button>
						<button id="btnDc" class="btn btn-default" type="button" onclick="btnDownExcelHandler()">导出</button>
					</td>
				</tr>
			</table>
		</form>

		<form id="downForm" action="downloadToExcel.service" enctype="multipart/form-data"></form>
	</div>
	<table id="dgForm"></table>
</div>
<script type="text/html" id="tableToolBar">
	<div>
		<a class="tableToolBarBtn" action="update" id=PTJGID href="javascript:void(0)" title="修改" style="color: #00c297;">修改</a>&nbsp;
		<a class="tableToolBarBtn" action="configZyjr" id=PTJGID href="javascript:void(0)" title="配置接入信息" style="color: #00c297;">配置接入信息</a>&nbsp;
		<a class="tableToolBarBtn" action="query" href="javascript:void(0)" title="查看" style="color: #00c297;">查看</a>
	</div>
</script>
</body>
</html>


















































